package com.douqu.game.core.config.common;

import com.douqu.game.core.entity.EntityObject;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LogUtils;

/**
 * Created by bean on 2017/7/14.
 */
public class CommonData extends EntityObject {

    public int id;

    public int value;

    public CommonData(String value)
    {
        String[] strs = value.split(ConstantFactory.SEMICOLON);
        this.id = Integer.parseInt(strs[0]);
        this.value = Integer.parseInt(strs[1]);

    }


    public CommonData(int id, int value)
    {
        this.id = id;
        this.value = value;
    }

    public CommonData(){}


    public SGCommonProto.CommonObject.Builder parseCommonObject()
    {
        SGCommonProto.CommonObject.Builder data = SGCommonProto.CommonObject.newBuilder();
        data.setId(id);
        data.setValue(value);
        return data;
    }


    public boolean checkAsset(Class cls, String key, int parentId)
    {
        if(DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(DataFactory.ASSET_KEY, id) == null)
        {
            LogUtils.error(cls.getSimpleName() + " Load " + key + " Error -> id:" + id + " value:" + value + " parentId:" + parentId);
            return false;
        }
        if(value <= 0)
        {
            LogUtils.error(cls.getSimpleName() + " Load " + key + " Error -> value is Zero! parentId:" + parentId);
            return false;
        }
        return true;
    }



    public boolean check(Class cls, String key, int typeKey, int parentId, boolean... notCheckValue)
    {
        if(DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(typeKey, id) == null)
        {
            LogUtils.error(cls.getSimpleName() + " Load " + key + " Error -> id:" + id + " value:" + value + " parentId:" + parentId);
            return false;
        }
        if(notCheckValue.length == 0)
        {
//            if(value <= 0)
//            {
//                LogUtils.error(cls.getSimpleName() + " Load " + key + " Error -> value is Zero! parentId:" + parentId);
//                return false;
//            }
        }

        return true;
    }


    @Override
    public String toString() {
        return "{" +
                "id=" + id +
                ", value=" + value +
                '}';
    }
}
